/*{ range1 }*/
public class StoppableCounterThread extends Thread {
    protected boolean running = true;
/*{ end }*/
    protected String name = null;
    protected int max = 0;
    protected int delay = 0;

    public StoppableCounterThread(String name, int max, int delay) {
        this.name = name; this.max = max; this.delay = delay;
    }

/*{ range2 }*/

    public void run() {
        for (int i = 0; i < max && running; i++) {
            System.out.println(name + ": " + i);
            try {
                Thread.sleep(delay);  // Sleep for delay milliseconds
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void stopThread() {
    	running = false;
    }

    public void startThread() {
    	super.start();
    }
}
/*{ end }*/
